<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "order".
 *
 * @property int $id
 * @property string $ext_order_id
 * @property string $increment_id
 * @property int $magento_order_id Magento里的order.id
 * @property string $payment_method 支付方式
 * @property int $storehouse_id 仓库ID
 * @property string $payment_status 支付状态
 * @property string $order_type
 * @property string $order_status 订单状态
 * @property string $last_track_status 修改订单地址，物流方式，产品时标记，打单专员确认变更
 * @property string $shipping_method 物流方式
 * @property string $shipping_method_origin 下单时客户选择的物流方式
 * @property string $shipping_description 物流描述
 * @property string $shipping_description_origin 下单时的物流描述
 * @property string $shipping_track_no 物流单号
 * @property string $waybill 本次发货的面单地址
 * @property int|null $payment_at 订单的支付时间
 * @property int $process_at 开始处理时间
 * @property int $has_shipment 是否发货
 * @property int|null $shipped_at 最后一次发货时间
 * @property int|null $shipped_count 最后一次发货数量
 * @property int $total_item_count 来自Magento，没发现用的地方
 * @property int $edited 订单是否处于编辑状态，编辑状态的订单不能配货，不能发货
 * @property int $approved 是否审核，1：审核通过，0：未审核
 * @property int $blocked 是否有未解决的联系客户
 * @property int $paused 待定
 * @property int $paused_uid 待定人
 * @property int $changed 换货次数
 * @property int $reshipped 重复次数
 * @property int $expedited 是否加急
 * @property int $created_at
 * @property int $updated_at
 * @property int $uid 创建订单的用户ID
 * @property int $website_id 订单来源的站点ID
 * @property int $store_id
 * @property string $from 订单来自PC端还是移动端
 * @property string $currency_code 订单币种
 * @property float $grand_total 最终支付的金额，退款会影响此值
 * @property float $base_grand_total 最终支付的金额（美元）
 * @property float $static_grand_total 最终支付的金额，但不再变化，退款不会影响此值
 * @property float $subtotal 购物车产品总价格
 * @property float $base_subtotal 购物车产品总价格（美元）
 * @property float $base_discount_amount 优惠券优惠的金额（美元）
 * @property float $base_shipping_amount 运费（美元）
 * @property float $shipping_amount 运费
 * @property float $discount_amount 优惠券优惠的金额
 * @property float $discount_points 消耗的积分
 * @property float $discount_points_amount 消耗的积分等价的金额
 * @property float $base_discount_points_amount 消耗的积分等价的金额
 （美元）
 * @property float $system_discount 系统折扣
 * @property string $discount_description 优惠描述
 * @property int $package_return 原件退回时，修改地址确定要不要取消旧面单重新生成新面单
 * @property float $shipping_insurance 来自Magento，全站是0，也没发现用的地方
 * @property float $shipping_discount_amount 运费优惠
 * @property float $base_shipping_discount_amount 运费优惠
 （美元）
 * @property float $store_credit_amount Store Credit抵扣，退款会影响此值
 * @property float $static_store_credit_amount Store Credit抵扣，但不再变化，退款不会影响此值
 * @property float $base_store_credit_amount Store Credit抵扣（美元）
 * @property float $gift_card_discount_amount 礼品卡抵扣
 * @property float $base_gift_card_discount_amount 礼品卡抵扣
 （美元）
 * @property int $ups_special UPS成人签收：1是，0否
 * @property int $has_gift 是否有赠品，需求变更后废弃，赠品在Magento里组装成item里的一个数组
 * @property int $has_prime_gift 生日礼物
 * @property string $transaction_id PayPal的交易号
 * @property int $presale 是否预售单
 * @property string $presale_timeline 预售时间|生产时间|发货时间
 * @property int $magento_return_id 自助退换货表主键
 * @property float $tariff_insurance_amount 关税保险金
 * @property float $base_tariff_insurance_amount 关税保险金(美金)
 * @property string $coupon_code 优惠券code
 * @property string $coupon_rule_name 优惠券规则名称
 * @property float $prime_discount_amount 会员抵扣，在Magento已经参与过运算了
 * @property float $base_prime_discount_amount 会员抵扣，在Magento已经参与过运算了
 （美元）
 * @property string $google_order_id Google Express里的order.id
 * @property float $shipping_tax_amount 此值全站是0
 * @property int $has_print_shipment_label 是否打印过面单
 * @property int $has_bundle 是否有套装
 * @property string $magento_user_lev_ordered 下单时客户等级
 * @property int $customer_id Magento里的用户ID
 * @property string $customer_group 客户下单时的等级
 * @property int $haiwaicang_export 海外仓是否导出
 * @property int $haiwaicang_export_uid 海外仓导出用户ID
 * @property string $guuid messenger发消息用
 * @property int $is_fraud 风控检测：是否涉嫌欺诈
 * @property string $distributor 分销哪个ERP
 * @property int $distributor_order_id 分销EPR里的order.id
 * @property string $source
 * @property int $blocked2
 * @property int $weight 本次发货重量，单位:g
 * @property int $sync_success 订单同步成功
 * @property string $email 冗余字段：客户邮箱
 * @property string|null $orders_type 订单种类N常规C定制
 */
class Order extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'order';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['increment_id', 'payment_method', 'shipping_method', 'shipping_method_origin', 'shipping_description', 'shipping_description_origin', 'shipping_track_no', 'waybill', 'currency_code', 'coupon_code', 'magento_user_lev_ordered', 'guuid', 'email'], 'required'],
            [['magento_order_id', 'storehouse_id', 'payment_at', 'process_at', 'has_shipment', 'shipped_at', 'shipped_count', 'total_item_count', 'edited', 'approved', 'blocked', 'paused', 'paused_uid', 'changed', 'reshipped', 'expedited', 'created_at', 'updated_at', 'uid', 'website_id', 'store_id', 'package_return', 'ups_special', 'has_gift', 'has_prime_gift', 'presale', 'magento_return_id', 'has_print_shipment_label', 'has_bundle', 'customer_id', 'haiwaicang_export', 'haiwaicang_export_uid', 'is_fraud', 'distributor_order_id', 'blocked2', 'weight', 'sync_success'], 'integer'],
            [['payment_status', 'order_type', 'order_status', 'last_track_status', 'from'], 'string'],
            [['grand_total', 'base_grand_total', 'static_grand_total', 'subtotal', 'base_subtotal', 'base_discount_amount', 'base_shipping_amount', 'shipping_amount', 'discount_amount', 'discount_points', 'discount_points_amount', 'base_discount_points_amount', 'system_discount', 'shipping_insurance', 'shipping_discount_amount', 'base_shipping_discount_amount', 'store_credit_amount', 'static_store_credit_amount', 'base_store_credit_amount', 'gift_card_discount_amount', 'base_gift_card_discount_amount', 'tariff_insurance_amount', 'base_tariff_insurance_amount', 'prime_discount_amount', 'base_prime_discount_amount', 'shipping_tax_amount'], 'number'],
            [['ext_order_id', 'distributor'], 'string', 'max' => 20],
            [['increment_id'], 'string', 'max' => 50],
            [['payment_method', 'coupon_code'], 'string', 'max' => 60],
            [['shipping_method', 'shipping_method_origin', 'shipping_description', 'shipping_description_origin', 'waybill', 'discount_description', 'transaction_id', 'presale_timeline', 'coupon_rule_name', 'google_order_id', 'customer_group', 'email'], 'string', 'max' => 255],
            [['shipping_track_no'], 'string', 'max' => 80],
            [['currency_code'], 'string', 'max' => 10],
            [['magento_user_lev_ordered'], 'string', 'max' => 100],
            [['guuid'], 'string', 'max' => 128],
            [['source'], 'string', 'max' => 30],
            [['orders_type'], 'string', 'max' => 2],
            [['increment_id'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'ext_order_id' => '订单号',
            'increment_id' => Yii::t('app', 'Increment ID'),
            'magento_order_id' => Yii::t('app', 'Magento Order ID'),
            'payment_method' => Yii::t('app', 'Payment Method'),
            'storehouse_id' => Yii::t('app', 'Storehouse ID'),
            'payment_status' => Yii::t('app', 'Payment Status'),
            'order_type' => Yii::t('app', 'Order Type'),
            'order_status' => Yii::t('app', 'Order Status'),
            'last_track_status' => Yii::t('app', 'Last Track Status'),
            'shipping_method' => Yii::t('app', 'Shipping Method'),
            'shipping_method_origin' => Yii::t('app', 'Shipping Method Origin'),
            'shipping_description' => Yii::t('app', 'Shipping Description'),
            'shipping_description_origin' => Yii::t('app', 'Shipping Description Origin'),
            'shipping_track_no' => Yii::t('app', 'Shipping Track No'),
            'waybill' => Yii::t('app', 'Waybill'),
            'payment_at' => Yii::t('app', 'Payment At'),
            'process_at' => Yii::t('app', 'Process At'),
            'has_shipment' => Yii::t('app', 'Has Shipment'),
            'shipped_at' => Yii::t('app', 'Shipped At'),
            'shipped_count' => Yii::t('app', 'Shipped Count'),
            'total_item_count' => Yii::t('app', 'Total Item Count'),
            'edited' => Yii::t('app', 'Edited'),
            'approved' => Yii::t('app', 'Approved'),
            'blocked' => Yii::t('app', 'Blocked'),
            'paused' => Yii::t('app', 'Paused'),
            'paused_uid' => Yii::t('app', 'Paused Uid'),
            'changed' => Yii::t('app', 'Changed'),
            'reshipped' => Yii::t('app', 'Reshipped'),
            'expedited' => Yii::t('app', 'Expedited'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'uid' => Yii::t('app', 'Uid'),
            'website_id' => Yii::t('app', 'Website ID'),
            'store_id' => Yii::t('app', 'Store ID'),
            'from' => Yii::t('app', 'From'),
            'currency_code' => Yii::t('app', 'Currency Code'),
            'grand_total' => Yii::t('app', 'Grand Total'),
            'base_grand_total' => Yii::t('app', 'Base Grand Total'),
            'static_grand_total' => Yii::t('app', 'Static Grand Total'),
            'subtotal' => Yii::t('app', 'Subtotal'),
            'base_subtotal' => Yii::t('app', 'Base Subtotal'),
            'base_discount_amount' => Yii::t('app', 'Base Discount Amount'),
            'base_shipping_amount' => Yii::t('app', 'Base Shipping Amount'),
            'shipping_amount' => Yii::t('app', 'Shipping Amount'),
            'discount_amount' => Yii::t('app', 'Discount Amount'),
            'discount_points' => Yii::t('app', 'Discount Points'),
            'discount_points_amount' => Yii::t('app', 'Discount Points Amount'),
            'base_discount_points_amount' => Yii::t('app', 'Base Discount Points Amount'),
            'system_discount' => Yii::t('app', 'System Discount'),
            'discount_description' => Yii::t('app', 'Discount Description'),
            'package_return' => Yii::t('app', 'Package Return'),
            'shipping_insurance' => Yii::t('app', 'Shipping Insurance'),
            'shipping_discount_amount' => Yii::t('app', 'Shipping Discount Amount'),
            'base_shipping_discount_amount' => Yii::t('app', 'Base Shipping Discount Amount'),
            'store_credit_amount' => Yii::t('app', 'Store Credit Amount'),
            'static_store_credit_amount' => Yii::t('app', 'Static Store Credit Amount'),
            'base_store_credit_amount' => Yii::t('app', 'Base Store Credit Amount'),
            'gift_card_discount_amount' => Yii::t('app', 'Gift Card Discount Amount'),
            'base_gift_card_discount_amount' => Yii::t('app', 'Base Gift Card Discount Amount'),
            'ups_special' => Yii::t('app', 'Ups Special'),
            'has_gift' => Yii::t('app', 'Has Gift'),
            'has_prime_gift' => Yii::t('app', 'Has Prime Gift'),
            'transaction_id' => Yii::t('app', 'Transaction ID'),
            'presale' => Yii::t('app', 'Presale'),
            'presale_timeline' => Yii::t('app', 'Presale Timeline'),
            'magento_return_id' => Yii::t('app', 'Magento Return ID'),
            'tariff_insurance_amount' => Yii::t('app', 'Tariff Insurance Amount'),
            'base_tariff_insurance_amount' => Yii::t('app', 'Base Tariff Insurance Amount'),
            'coupon_code' => Yii::t('app', 'Coupon Code'),
            'coupon_rule_name' => Yii::t('app', 'Coupon Rule Name'),
            'prime_discount_amount' => Yii::t('app', 'Prime Discount Amount'),
            'base_prime_discount_amount' => Yii::t('app', 'Base Prime Discount Amount'),
            'google_order_id' => Yii::t('app', 'Google Order ID'),
            'shipping_tax_amount' => Yii::t('app', 'Shipping Tax Amount'),
            'has_print_shipment_label' => Yii::t('app', 'Has Print Shipment Label'),
            'has_bundle' => Yii::t('app', 'Has Bundle'),
            'magento_user_lev_ordered' => Yii::t('app', 'Magento User Lev Ordered'),
            'customer_id' => Yii::t('app', 'Customer ID'),
            'customer_group' => Yii::t('app', 'Customer Group'),
            'haiwaicang_export' => Yii::t('app', 'Haiwaicang Export'),
            'haiwaicang_export_uid' => Yii::t('app', 'Haiwaicang Export Uid'),
            'guuid' => Yii::t('app', 'Guuid'),
            'is_fraud' => Yii::t('app', 'Is Fraud'),
            'distributor' => Yii::t('app', 'Distributor'),
            'distributor_order_id' => Yii::t('app', 'Distributor Order ID'),
            'source' => Yii::t('app', 'Source'),
            'blocked2' => Yii::t('app', 'Blocked2'),
            'weight' => Yii::t('app', 'Weight'),
            'sync_success' => Yii::t('app', 'Sync Success'),
            'email' => Yii::t('app', 'Email'),
            'orders_type' => Yii::t('app', 'Orders Type'),
        ];
    }

    public function getAddress()
    {
        return $this->hasMany(OrderAddress::class, ['order_id'=>'id']);
    }
}
